package contest;

import java.io.*;
import java.util.*;

public class TheHousofHugeFamily {
	public static void main(String args[]){
		Scanner sc = new Scanner(new InputStreamReader(System.in));
		while(true){
			int value1 = sc.nextInt();
			int value2 = sc.nextInt();
			if(value1==0 && value2 ==0)break;
			int[] start = new int[value2];
			int[] end = new int[value2];
			int[] cost = new int[value2];
			for(int i=0;i<value2;i++){
				start[i] = sc.nextInt();
				end[i] = sc.nextInt();
				cost[i] = sc.nextInt();
			}
			
		}
	}
}
